

var vm = new Vue({
    el:"#app",
    data:{
        role:'',
        addFlag:''
    },
    methods:{
        getRole:function () {
            axios.post("/role/queryRolesForAdd").then(
                function(result){
                    vm.role=result.data;
                    console.log(vm.role);
                },function (err) {
                    console.log(err);
                }
            )
        },
        addRole:function (){
            let flag = true;
            let roleName = $("input[name='roleName']").val();
            if (roleName === ""){
                flag = false;
            }
            let modules = [];
            let count = 0;
            for(let i = 0;i<6;i++){
                if ($(".module"+i).attr("checked")){
                    modules.push($(".module"+i).val());
                    count++;
                }
            }
            if (count < 0){
                flag = false;
            }
            if (flag){
                axios.post("/role/addRole",{roleName:roleName,modules:modules}).then(
                    function(result){
                        vm.addFlag = result.data;
                        console.log(vm.addFlag);
                        if (vm.addFlag){
                            alert("添加角色成功");
                            location.href = "../../../../templates/sysManage/roleManage/roleList.html";
                        }else {
                            alert("添加角色失败");
                        }
                    },function (err) {
                        console.log(err);
                    }
                )
            }else {
                alert("您的信息还未填写完全");
            }
        }
    },
    //页面加载完自动执行
    mounted(){
        this.getRole();
    }
})
